home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 24 / AACD 24.iso / AACD / System / ReqToolsLib / Source / reqtools / filereqextra.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-07-02  |  37.3 KB  |  1,536 lines

  1. /*
  2.     (C) 2000-2001 AROS - The Amiga Research OS
  3.     $Id: filereqextra.c,v 1.8 2001/05/03 19:12:32 stegerg Exp $
  4.  
  5.     Desc:
  6.     Lang: English
  7. */
  8.  
  9. /**************************************************************
  10. *                                                             *
  11. *      File/Font/Screenmode requester                         *
  12. *                                                             *
  13. *                                 (c) Nico François 1991-1994 *
  14. **************************************************************/
  15.  
  16. #include "filereq.h"
  17.  
  18.  
  19. #ifdef   _AROS
  20.  
  21.     #define  DEBUG  0
  22.     #include <aros/debug.h>
  23.  
  24. #else
  25.  
  26.     #define  D(x)  
  27.  
  28. #endif
  29.  
  30.  
  31. /****************************************************************************************/
  32.  
  33. extern struct LocaleBase *LocaleBase;
  34.  
  35. /****************************************************************************************/
  36.  
  37. static void REGARGS MarkHidden (GlobData *);
  38. static int REGARGS SkipEntry (GlobData *, struct ReqEntry *);
  39.  
  40. /****************************************************************************************/
  41.  
  42. /********************
  43. * Requester Display *
  44. ********************/
  45.  
  46. /****************************************************************************************/
  47.  
  48. void REGARGS AdjustScroller (GlobData *glob)
  49. {
  50.     myGT_SetGadgetAttrs (glob->scrollergad, glob->reqwin, NULL, GTSC_Total, glob->buff->currentnum,
  51.                                     GTSC_Top, glob->buff->gotopos,
  52.                                 TAG_END);
  53. }
  54.  
  55. /****************************************************************************************/
  56.  
  57. void REGARGS ClearFilesRect (GlobData *glob)
  58. {
  59.     SetAPen (glob->reqrp, glob->pens[BACKGROUNDPEN]);
  60.     mySetWriteMask (glob->reqrp, glob->entrymask);
  61.     RectFill (glob->reqrp, glob->boxleft, glob->boxtop - 1, glob->boxright,
  62.                  glob->boxtop + glob->boxheight);
  63.     mySetWriteMask (glob->reqrp, glob->rpmask);
  64. }
  65.  
  66. /****************************************************************************************/
  67.  
  68. void REGARGS ScrollerMoved (GlobData *glob, int code)
  69. {
  70.     glob->buff->gotopos = code;
  71.     if (!glob->buff->sorted)
  72.     {
  73.     glob->buff->pos = glob->buff->gotopos;
  74.     UpdateDisplayList (glob);
  75.     PrintFiles (glob);
  76.     AdjustScroller (glob);
  77.     glob->buff->sorted = TRUE;
  78.     }
  79. }
  80.  
  81. /****************************************************************************************/
  82.  
  83. static void REGARGS MarkHidden (GlobData *glob)
  84. {
  85.     struct ReqEntry     *entry;
  86.     int         skipflags;
  87.     
  88.     if (glob->nodir) return;
  89.     
  90.     for (entry = (struct ReqEntry *)glob->firstentry->re_Next;
  91.      entry;
  92.      entry = (struct ReqEntry *)entry->re_Next)
  93.     {
  94.     entry->re_Flags &= ~(ENTRYF_HIDDEN|ENTRYF_GHOSTED);
  95.     if ((skipflags = SkipEntry (glob, entry))) entry->re_Flags |= skipflags;
  96.     }
  97. }
  98.  
  99. /****************************************************************************************/
  100.  
  101. void REGARGS RethinkReqDisplay (GlobData *glob)
  102. {
  103.     int num;
  104.  
  105.     if (glob->nodir) return;
  106.     
  107.     MarkHidden (glob);
  108.     num = (glob->buff->currentnum = CountAllDeselect (glob, FALSE))
  109.                                                                                 - glob->numentries;
  110.     if (num < 0) glob->buff->gotopos = glob->buff->pos = 0;
  111.     else if (glob->buff->pos > num) glob->buff->gotopos = glob->buff->pos = num;
  112.     
  113.     AdjustScroller (glob);
  114.     UpdateDisplayList (glob);
  115.     PrintFiles (glob);
  116. }
  117.  
  118. /****************************************************************************************/
  119.  
  120. void REGARGS ClearDisplayList (GlobData *glob)
  121. {
  122.     memset (glob->displaylist, 0, 50*4);
  123. }
  124.  
  125. /****************************************************************************************/
  126.  
  127. void REGARGS UpdateDisplayList (GlobData *glob)
  128. {
  129.     struct ReqEntry     *entry;
  130.     int         i;
  131.  
  132.     i = 0;
  133.  
  134.     if (glob->buff->currentnum &&
  135.     (entry = (struct ReqEntry *)glob->firstentry->re_Next))
  136.     {
  137.     while (i < glob->buff->pos)
  138.     {
  139.         if (!(entry->re_Flags & ENTRYF_HIDDEN))
  140.         {
  141.         i++;
  142.         }
  143.         
  144.         entry = (struct ReqEntry *)entry->re_Next;
  145.     }
  146.  
  147.     
  148.     for (i = 0; entry && (i < glob->numentries); 
  149.          entry = (struct ReqEntry *)entry->re_Next)
  150.     {
  151.         if (!(entry->re_Flags & ENTRYF_HIDDEN))
  152.         {
  153.         glob->displaylist[i++] = entry;
  154.         }
  155.     }
  156.     }
  157.     
  158.     while (i < glob->numentries)
  159.     {
  160.     glob->displaylist[i++] = NULL;
  161.     }
  162. }
  163.  
  164. /****************************************************************************************/
  165.  
  166. static UWORD GhostPattern[] = { 0x4444, 0x1111 };
  167.  
  168. /****************************************************************************************/
  169.  
  170. /* Apply a ghosting pattern to a given rectangle in a rastport */
  171. static void REGARGS Ghost (struct RastPort *rp, UWORD pen, UWORD x, UWORD y, UWORD w, UWORD h)
  172. {
  173.     SetAPen (rp, pen);
  174.     SetBPen (rp, pen);
  175.     SetDrMd (rp, JAM1);
  176.     SetAfPt (rp, GhostPattern, 1);
  177.     RectFill (rp, x, y, x + w - 1, y + h - 1);
  178.     SetAfPt (rp, NULL, 0);
  179. }
  180.  
  181. /****************************************************************************************/
  182.  
  183. void REGARGS PrintEntry (GlobData *glob, int i)
  184. {
  185.     struct TextExtent     extent;
  186.     struct ReqEntry     *entry;
  187.     struct RastPort     *reqrp = glob->reqrp;
  188.     char         sizestr[16], tempstr[108], *volname = NULL, *str;
  189.     int         apen, bpen, top, len, sizelen, sizelenpix, type, rectpen, left, entrytop;
  190.     LONG         size;
  191.  
  192.     mySetWriteMask (glob->reqrp, glob->entrymask);
  193.     rectpen = BACKGROUNDPEN;
  194.     
  195.     if ((entry = glob->displaylist[i]))
  196.     {
  197.     strcpy (tempstr, entry->re_Name);
  198.     apen = TEXTPEN; bpen = BACKGROUNDPEN;
  199.     sizestr[0] = 0;
  200.     size = entry->re_Size;
  201.     type = entry->re_Type;
  202.     if (type == glob->directory_id)
  203.     {
  204.         strcpy (sizestr, GetStr (glob->catalog, MSG_DRAWER));
  205.         apen = HIGHLIGHTTEXTPEN;
  206.     }
  207.     else if (type == FONT || (type == glob->file_id))
  208.     {
  209. #ifdef _AROS
  210. #warning AROS LocaleLibrary does not yet patch RawDoFmt. So "%lD" (uppercase D) does not work yet here!
  211.         Dofmt (sizestr, " %ld", &size);
  212. #else
  213.         Dofmt (sizestr, LocaleBase ? " %lD" : " %ld", &size);
  214. #endif
  215.         if (type == FONT)
  216.         {
  217.         StrCat (tempstr, sizestr);
  218.         sizestr[0] = 0;
  219.         }
  220.     }
  221.     else if (type == ASSIGN)
  222.     {
  223.         strcpy (sizestr, GetStr (glob->catalog, MSG_ASSIGN));
  224.         apen = HIGHLIGHTTEXTPEN;
  225.     }
  226.     else if (type == VOLUME)
  227.     {
  228.         if (size >= 0) Dofmt (sizestr, GetStr (glob->catalog, MSG_FULL), &size);
  229.     }
  230.  
  231.     if (type == VOLUME && entry->re_VolLen)
  232.     {
  233.          len = entry->re_VolLen;
  234.          volname = entry->re_Name + len + 1;
  235.     }
  236.     else
  237.         len = strlen (tempstr);
  238.  
  239.     sizelen = strlen (sizestr);
  240.     /* Cache the pixel size for each entry so
  241.         we only have to calculate this once. */
  242.     if (entry->re_SizeLenPix)
  243.         sizelenpix = entry->re_SizeLenPix;
  244.     else
  245.     {
  246.         if (sizestr[0])
  247.             sizelenpix = StrWidth_noloc (&glob->itxt, sizestr);
  248.         else
  249.             sizelenpix = 0;
  250.         
  251.         if (sizelenpix < 256) entry->re_SizeLenPix = sizelenpix;
  252.     }
  253.  
  254.     if (entry->re_Flags & ENTRYF_SELECTED)
  255.     {
  256.         bpen = FILLPEN;
  257.         if (type == glob->directory_id || type == ASSIGN)
  258.         {
  259.         apen = BACKGROUNDPEN;
  260.         bpen = HIGHLIGHTTEXTPEN;
  261.         }
  262.         else /* VOLUME, FILE, FONT */
  263.         apen = FILLTEXTPEN;
  264.         
  265.         rectpen = bpen;
  266.     }
  267.         
  268.     } /* if ((entry = glob->displaylist[i])) */
  269.     else
  270.     {
  271.     if (glob->lastdisplaylistnum == -1) glob->lastdisplaylistnum = i;
  272.     }
  273.     
  274.     top = glob->boxtop + i * glob->entryheight;
  275.     SetDrMd (glob->reqrp, JAM2);
  276.     SetAPen (reqrp, glob->pens[rectpen]);
  277.     entrytop = top;
  278.     RectFill (reqrp, glob->boxleft, entrytop, glob->boxright, entrytop + glob->entryheight - 1);
  279.  
  280.     if (entry)
  281.     {
  282.     SetAPen (reqrp, glob->pens[apen]);
  283.     SetBPen (reqrp, glob->pens[bpen]);
  284.     top += glob->fontbase + 1;
  285.     str = tempstr;
  286.     left = glob->boxleft + 2;
  287.     Move (reqrp, left, top);
  288.     
  289.     if (volname)
  290.     {
  291.         Text (reqrp, volname, strlen (volname));
  292.         left += glob->maxvolwidth;
  293.         Move (reqrp, left, top);
  294.     }
  295.     
  296.     /* Cache entry length, so we only need to calculate this once */
  297.     if (!entry->re_EntryLen)
  298.     {
  299.          len = TextFit (reqrp, str, len, &extent, NULL, 1,
  300.                              glob->boxright - left - sizelenpix - 5, glob->entryheight);
  301.          entry->re_EntryLen = len;
  302.     }
  303.     else len = entry->re_EntryLen;
  304.     
  305.     Text (reqrp, str, len);
  306.     
  307.     if (sizelenpix)
  308.     {
  309.          Move (reqrp, glob->boxright - sizelenpix - 1, top);
  310.          Text (reqrp, sizestr, sizelen);
  311.     }
  312.     
  313.     if (entry->re_Flags & ENTRYF_GHOSTED)
  314.     {
  315.         Ghost (reqrp, glob->pens[BACKGROUNDPEN],
  316.               glob->boxleft, entrytop,
  317.               glob->boxright - glob->boxleft + 1, glob->entryheight);
  318.     }
  319.     
  320.     } /* if (entry) */
  321.         
  322.     mySetWriteMask (glob->reqrp, glob->rpmask);
  323. }
  324.  
  325. /****************************************************************************************/
  326.  
  327. void REGARGS PrintFiles (GlobData *glob)
  328. {
  329.     int i;
  330.  
  331.     glob->lastdisplaylistnum = -1;
  332.     for (i = 0; i < glob->numentries; i++)
  333.     {
  334.     PrintEntry (glob, i);
  335.     }
  336. }
  337.  
  338. /****************************************************************************************/
  339.  
  340. /********************
  341. * Requester entries *
  342. ********************/
  343.  
  344. /****************************************************************************************/
  345.  
  346. void REGARGS ClearAndInitReqBuffer (GlobData *glob)
  347. {
  348.     glob->buff->gotopos = glob->buff->pos = glob->buff->currentnum = glob->buff->numfiles = 0;
  349.     glob->firstentry = (struct ReqEntry *)AllocVecPooled(glob->buff->pool, sizeof (struct ReqEntry));
  350.     glob->buff->firstname = glob->firstentry;
  351. }
  352.  
  353. /****************************************************************************************/
  354.  
  355. static UBYTE *REGARGS SkipDevName (UBYTE *entryname)
  356. {
  357.     while (*entryname != ' ') entryname++;
  358.     while (*entryname == ' ') entryname++;
  359.  
  360.     return (entryname);
  361. }
  362.  
  363. /****************************************************************************************/
  364.  
  365. struct ReqEntry *REGARGS FindEntry (struct BufferData *buff, char *name, int size,
  366.                     int ctype, int *pos, ULONG flags)
  367. {
  368.     struct ReqEntry     *curr, *lastname;
  369.     int         lastcmp, cmp, i = 0, cmptype;
  370.     UBYTE         *entryname;
  371.  
  372.     lastname = buff->firstname;
  373.     curr = (struct ReqEntry *)lastname->re_Next;
  374.     if ((ctype <= MAX_FILE_DIRECTORY) && buff->dirsmixed)
  375.     {
  376.     cmptype = 1;
  377.     }
  378.     else
  379.     {
  380.     while (curr && curr->re_Type < ctype)
  381.     {
  382.         lastname = curr;
  383.         if (!(lastname->re_Flags & ENTRYF_HIDDEN)) i++;
  384.         curr = (struct ReqEntry *)curr->re_Next;
  385.     }
  386.     cmptype = ctype;
  387.     }
  388.     
  389.     lastcmp = 1;
  390.     while (curr)
  391.     {
  392.     if (ctype >= 0 && curr->re_Type > cmptype) break;
  393.     entryname = curr->re_Name;
  394.     
  395.     if (curr->re_Type == VOLUME && !(flags & FIND_VOLUMENAME))
  396.     {
  397.         cmp = Strnicmp (name, entryname, strlen(name));
  398.     }
  399.     else
  400.     {
  401.         if (curr->re_Type == VOLUME && (flags & FIND_VOLUMENAME))
  402.             entryname = SkipDevName (entryname);
  403.         cmp = Stricmp (name, entryname);
  404.     }
  405.     
  406.     if ((cmp < 0) || (!cmp && (size < curr->re_Size))) break;
  407.     
  408.     lastcmp = cmp;
  409.     lastname = curr;
  410.     
  411.     if (!(lastname->re_Flags & ENTRYF_HIDDEN)) i++;
  412.     
  413.     curr = (struct ReqEntry *)curr->re_Next;
  414.     }
  415.     
  416.     if (pos)
  417.     {
  418.     if (lastname && (!(flags & FIND_EXACT) || !lastcmp))
  419.     {
  420.         *pos = i - 1;
  421.         return (lastname);
  422.     }
  423.     else 
  424.     {
  425.         *pos = 0;
  426.         return (NULL);
  427.     }
  428.     }
  429.     
  430.     return (lastname);
  431. }
  432.  
  433. /****************************************************************************************/
  434.  
  435. struct ReqEntry *REGARGS AddEntry (GlobData *glob, struct BufferData *buff,
  436.                 char *name, int size, int ctype)
  437. {
  438.     struct ReqEntry    *lastname, *newentry;
  439.     int            pos, len = strlen( name ) + 1, currnum, skipflags;
  440.     STRPTR        str, findname = name;
  441.  
  442.     if( ctype == VOLUME )
  443.     {
  444.     findname = SkipDevName( findname );
  445.     }
  446.  
  447.     lastname = FindEntry( buff, findname, ( ( ctype == FONT ) ? size : MAXINT) ,
  448.                   ctype, &pos, FIND_VOLUMENAME );
  449.  
  450.     str = lastname->re_Name;
  451.  
  452.     if( str && !Stricmp( name, str ) )
  453.     {
  454.     if( ctype <= MAX_FILE_DIRECTORY )
  455.     {
  456.         lastname->re_Size = size;
  457.         return( lastname );
  458.     }
  459.  
  460.     len = 0;
  461.     }
  462.  
  463.     if( !( newentry = ( struct ReqEntry * ) AllocVecPooled(buff->pool, sizeof( struct ReqEntry ) + len ) ) )
  464.     {
  465.     return( NULL );
  466.     }
  467.  
  468.     if( len )
  469.     {
  470.     str = ( STRPTR ) newentry + sizeof( struct ReqEntry );
  471.     strcpy( str, name );
  472.     }
  473.  
  474.     newentry->re_Name = str;
  475.     newentry->re_Size = size;
  476.     newentry->re_Type = ctype;
  477.     newentry->re_Next = lastname->re_Next;
  478.     lastname->re_Next = ( struct Node * ) newentry;
  479.  
  480.     buff->numfiles++;
  481.     buff->sorted = FALSE;
  482.  
  483.     if( glob )
  484.     {
  485.     skipflags = SkipEntry( glob, newentry );
  486.     newentry->re_Flags |= skipflags;
  487.  
  488.     if( skipflags != ENTRYF_HIDDEN )
  489.     {
  490.         /* If file requester keep activated itempos up to date */
  491.         if( ctype <= MAX_FILE_DIRECTORY )
  492.         {
  493.         if( pos < glob->selectedpos )
  494.         {
  495.             glob->selectedpos++;
  496.         }
  497.         }
  498.  
  499.         currnum = buff->currentnum;
  500.         buff->currentnum++;
  501.  
  502.         if( ctype <= MAX_FILE_DIRECTORY )
  503.         {    /* display now ? */
  504.         if (currnum < glob->numentries)
  505.         {
  506.             glob->displaylist[currnum] = newentry;
  507.  
  508.             if( !glob->quiet )
  509.             {
  510.             PrintEntry( glob, currnum );
  511.             }
  512.         }
  513.         else if( !glob->quiet )
  514.         {
  515.             AdjustScroller( glob );
  516.         }
  517.         }
  518.     }
  519.     }
  520.  
  521.     return( newentry );
  522. }
  523.  
  524. /****************************************************************************************/
  525.  
  526. int REGARGS EndsInDotInfo (char *str, int len)
  527. {
  528.     if (len >= 5 && !Stricmp (&str[len-5], DOTINFOSTR)) return (TRUE);
  529.     return (FALSE);
  530. }
  531.  
  532. /****************************************************************************************/
  533.  
  534. static int REGARGS SkipEntry (GlobData *glob, struct ReqEntry *entry)
  535. {
  536.     char *str = entry->re_Name;
  537.     int  len = strlen (str);
  538.  
  539.     if (glob->reqtype == RT_FILEREQ)
  540.     {
  541.     if (entry->re_Type == glob->file_id)
  542.     {
  543.         if (!glob->wilddotinfo)
  544.         {
  545.         if (EndsInDotInfo (str, len))
  546.         {
  547.             if (glob->freq->hideinfo) return (ENTRYF_HIDDEN);
  548.             
  549.             if (glob->matchpat[0])
  550.             {
  551.             int ret;
  552.  
  553.             str[len-5] = '\0';
  554.             ret = !MatchPatternNoCase (glob->matchpat, str);
  555.             str[len-5] = '.';
  556.             
  557.             return (ret ? ENTRYF_HIDDEN : 0);
  558.             }
  559.         }
  560.         }
  561.         
  562.         if (glob->flags & FREQF_NOFILES) return (ENTRYF_GHOSTED);
  563.         
  564.         if (glob->matchpat[0])
  565.         if (!MatchPatternNoCase (glob->matchpat, str))
  566.             return (ENTRYF_HIDDEN);
  567.     }
  568.     }
  569.     else if (glob->reqtype == RT_FONTREQ)
  570.     {
  571.         if (entry->re_Size < glob->minsize || entry->re_Size > glob->maxsize ||
  572.         ((glob->flags & FREQF_FIXEDWIDTH) && (entry->re_Flags & FPF_PROPORTIONAL)) ||
  573.         (!(glob->flags & FREQF_COLORFONTS) && (entry->re_Style & FSF_COLORFONT)))
  574.          return (ENTRYF_HIDDEN);
  575.     }
  576.     else
  577.     {
  578.     ;
  579.     }
  580.     
  581.     return (0);
  582. }
  583.  
  584. /****************************************************************************************/
  585.  
  586. int REGARGS CountAllDeselect (GlobData *glob, int dirsonly)
  587. {
  588.     struct ReqEntry     *entry;
  589.     int         count = 0;
  590.  
  591.     for (entry = (struct ReqEntry *)glob->firstentry->re_Next;
  592.      entry;
  593.      entry = (struct ReqEntry *)entry->re_Next)
  594.     {
  595.     if (!(entry->re_Flags & ENTRYF_HIDDEN)) count++;
  596.     if (!dirsonly || entry->re_Type != glob->file_id)
  597.     {
  598.         if (entry->re_Flags & ENTRYF_SELECTED)
  599.         {
  600.         glob->numselected--;
  601.         entry->re_Flags &= ~ENTRYF_SELECTED;
  602.         }
  603.     }
  604.     }
  605.     
  606.     glob->selectedpos = -1;
  607.     
  608.     return (count);
  609. }
  610.  
  611. /****************************************************************************************/
  612.  
  613. void REGARGS SelectAll (GlobData *glob, char *pattern)
  614. {
  615.     struct ReqEntry     *entry;
  616.     char         selpat[124];
  617.  
  618.     ParsePatternNoCase (pattern, selpat, 124);
  619.     
  620.     for (entry = (struct ReqEntry *)glob->firstentry->re_Next;
  621.      entry;
  622.      entry = (struct ReqEntry *)entry->re_Next)
  623.     { 
  624.     if (!(entry->re_Flags & (ENTRYF_HIDDEN|ENTRYF_GHOSTED)))
  625.     {
  626.         if ((entry->re_Type == glob->file_id) ||
  627.             (entry->re_Type == glob->directory_id && (glob->flags & FREQF_SELECTDIRS)))
  628.         {
  629.         if (MatchPatternNoCase (selpat, entry->re_Name))
  630.         {
  631.             if (!(entry->re_Flags & ENTRYF_SELECTED)) glob->numselected++;
  632.             entry->re_Flags |= ENTRYF_SELECTED;
  633.         }
  634.         }
  635.     }
  636.     }
  637.     
  638.     UpdateNumSelGad (glob);
  639.     PrintFiles (glob);
  640.     my_SetStringGadget (glob->reqwin, glob->filegad, NULL);
  641. }
  642.  
  643. /****************************************************************************************/
  644.  
  645. /*****************
  646. * File requester *
  647. *****************/
  648.  
  649. /****************************************************************************************/
  650.  
  651. void REGARGS UnLockReqLock (GlobData *glob)
  652. {
  653.     glob->ledon = FALSE;
  654.     RenderLED (glob);
  655.     if (glob->lock) UnLock (glob->lock);
  656.     glob->lock = NULL;
  657. }
  658.  
  659. /****************************************************************************************/
  660.  
  661. BOOL REGARGS FindVolume (GlobData *glob, UBYTE *str, struct ReqEntry *curr)
  662. {
  663.     struct ReqEntry     *entry;
  664.     UBYTE         *s;
  665.  
  666.     for (entry = (struct ReqEntry *)glob->firstentry->re_Next;
  667.      entry;
  668.      entry = (struct ReqEntry *)entry->re_Next)
  669.     {
  670.     if (entry != curr && entry->re_Type == VOLUME)
  671.     {
  672.         s = entry->re_Name;
  673.         while (*s != ' ') s++;
  674.         while (*s == ' ') s++;
  675.         if (!Stricmp (s, str)) return (TRUE);
  676.     }
  677.     }
  678.     
  679.     return (FALSE);
  680. }
  681.  
  682. /****************************************************************************************/
  683.  
  684. static BOOL
  685. IsDosVolume(struct DosList *dlist)
  686. {
  687. #ifdef _AROS
  688.     struct InfoData id;
  689.     BPTR            lock;
  690.     STRPTR          volName = AllocVec(strlen(dlist->dol_DevName) + 2,
  691.                        MEMF_ANY);
  692.  
  693.     /* Create a colon ended volume name, lock it and call Info() */
  694.  
  695.     if (volName == NULL)
  696.     {
  697.     return FALSE;
  698.     }
  699.  
  700.     strcpy(volName, dlist->dol_DevName);
  701.     strcat(volName, ":");
  702.  
  703.     lock = Lock(volName, SHARED_LOCK);
  704.  
  705.     if (lock != NULL)
  706.     {
  707.     BOOL result = Info(lock, &id);
  708.  
  709.     UnLock(lock);
  710.     FreeVec(volName);
  711.  
  712.     return result;
  713.     } 
  714.     else
  715.     {
  716.     FreeVec(volName);
  717.  
  718.     return FALSE;
  719.     }
  720.  
  721. #else
  722.  
  723.     BOOL    isdev = FALSE;
  724.     D_S( struct InfoData,id );
  725.  
  726.     if( !dlist->dol_Task || DoPkt1( dlist->dol_Task, ACTION_DISK_INFO, MKBADDR( id ) ) )
  727.     {
  728.     isdev = TRUE;
  729.     }
  730.  
  731.     return (isdev);
  732. #endif
  733.  
  734. }
  735.  
  736. /****************************************************************************************/
  737.  
  738. static BOOL
  739. IsDosDevice( struct DosList *dlist )
  740. {
  741.     struct FileSysStartupMsg *fssm;
  742.     struct DosEnvec *de;
  743.     BOOL isdev = FALSE;
  744.  
  745.     /* If it`s a device, do the hard check for a filesystem */
  746.  
  747.     if (dlist->dol_Type == DLT_DEVICE)
  748.     {
  749.     fssm = ( struct FileSysStartupMsg * )BADDR( dlist->dol_misc.dol_handler.dol_Startup );
  750.  
  751.     if( fssm )
  752.     {
  753.         if( TypeOfMem( fssm ) && TypeOfMem( BADDR( fssm->fssm_Device ) )
  754.             && TypeOfMem( BADDR( fssm->fssm_Environ ) ) )
  755.         {
  756.         if( *( ( STRPTR ) BADDR( fssm->fssm_Device ) ) != 255 )
  757.         {
  758.             de = ( struct DosEnvec * ) BADDR( fssm->fssm_Environ );
  759.  
  760.             if( de && TypeOfMem( de ) )
  761.             {
  762.             if( de->de_Surfaces && de->de_BlocksPerTrack )
  763.             {
  764.                 isdev = TRUE;
  765.             }
  766.             }
  767.         }
  768.         }
  769.     }
  770. #ifdef TASK_DEVICE
  771.     else
  772.     {
  773.         isdev = ( dlist->dol_Task != NULL );
  774.     }
  775. #endif
  776.     }
  777.  
  778.     return( isdev );
  779. }
  780.  
  781. /****************************************************************************************/
  782.  
  783. struct DeviceEntry
  784. {
  785.     struct DeviceEntry    *next;
  786.     struct MsgPort    *task;
  787.     BOOL        resolved;
  788.     UBYTE        name[ 42 ];
  789. };
  790.  
  791. /****************************************************************************************/
  792.  
  793. #define SIZE_NONE    ( ( ULONG ) -1 )
  794. #define SIZE_CALCULATE    ( ( ULONG ) -2 )
  795.  
  796. /****************************************************************************************/
  797.  
  798. static void
  799. AddDisk(
  800.     GlobData *glob,
  801.     struct DeviceEntry *deventry,
  802.     UBYTE *devname,
  803.     ULONG size,
  804.     ULONG volreqflags )
  805. {
  806.     struct rtVolumeEntry    volentry;
  807.     struct ReqEntry        *entry;
  808.     UBYTE            buffer[80];
  809.     int             i, addentry;
  810.     
  811.     D_S( struct InfoData, infodata );
  812.  
  813.     addentry = TRUE;
  814.  
  815.     if( volreqflags && glob->filterhook )
  816.     {
  817.     volentry.Type = DLT_DEVICE;
  818.     volentry.Name = devname;
  819.     addentry = CallHookPkt( glob->filterhook, glob->freq, &volentry );
  820.     }
  821.  
  822.     if( addentry )
  823.     {
  824.     if( size == SIZE_CALCULATE )
  825.     {
  826.         size = SIZE_NONE;
  827.  
  828. #ifdef _AROS
  829.         {
  830.         BPTR lock = Lock(&deventry->name, SHARED_LOCK);
  831.  
  832.         if (lock != NULL)
  833.         {
  834.             if (Info(lock, infodata))
  835.             {
  836.             size = ( infodata->id_NumBlocksUsed * 100 +
  837.                  infodata->id_NumBlocks / 2 ) /
  838.                 infodata->id_NumBlocks;
  839.             }
  840.         }
  841.         }
  842. #else
  843.         if( deventry->task &&
  844.             DoPkt1( deventry->task, ACTION_DISK_INFO, MKBADDR( infodata ) ) )
  845.         {
  846.         size = ( infodata->id_NumBlocksUsed * 100 +
  847.              infodata->id_NumBlocks / 2 ) /
  848.             infodata->id_NumBlocks;
  849.         }
  850. #endif
  851.     }
  852.  
  853.     i = StrWidth_noloc( &glob->itxt, deventry->name ) + StrWidth_noloc( &glob->itxt, "W" );
  854.  
  855.     if( i > glob->maxvolwidth )
  856.     {
  857.         glob->maxvolwidth = i;
  858.     }
  859.  
  860.     DofmtArgs( buffer, "%s %s", devname, deventry->name );
  861.  
  862.     if( ( entry = AddEntry( glob, glob->buff, buffer, size, VOLUME ) ) )
  863.     {
  864.         entry->re_VolLen = strlen( devname );
  865.     }
  866.     }
  867. }
  868.  
  869. /****************************************************************************************/
  870.  
  871. static struct DeviceEntry *
  872. AllocDevEntry( GlobData *glob, struct DosList *dlist, STRPTR name )
  873. {
  874.     struct DeviceEntry    *deventry;
  875.  
  876.     if( ( deventry = ( struct DeviceEntry * ) AllocVecPooled(
  877.       glob->buff->pool, sizeof( struct DeviceEntry ) ) ) )
  878.     {
  879.     strcpy( deventry->name, name );
  880. #ifdef _AROS
  881. #warning FIXME: dlist->dol_Task does not exist in AROS. For now assuming 0 here.
  882.     deventry->task = NULL;
  883. #else
  884.     deventry->task = dlist->dol_Task;
  885. #endif
  886.     deventry->resolved = FALSE;
  887.     }
  888.  
  889.     return( deventry );
  890. }
  891.  
  892. /****************************************************************************************/
  893.  
  894. static void
  895. GetVolName( BSTR bstr, STRPTR cstr )
  896. {
  897. #ifdef _AROS
  898.     /* In AROS, BPTR:s are handled differently on different systems
  899.        (to be binary compatible on Amiga) */
  900.  
  901.     if (bstr != NULL)
  902.     {
  903.     LONG    length = AROS_BSTR_strlen(bstr);
  904.     LONG    i;        /* Loop variable */
  905.  
  906.     for (i = 0; i < length; i++)
  907.     {
  908.         cstr[i] = AROS_BSTR_getchar(bstr, i);
  909.     }
  910.     
  911.     cstr[i++] = ':';
  912.     cstr[i] = 0;
  913.  
  914.     D(bug("Found volume %s\n", cstr));
  915.     }
  916. #else
  917.     STRPTR str;
  918.  
  919.     *cstr = 0;
  920.  
  921.     if( ( str = BADDR( bstr ) ) )
  922.     {
  923.     LONG i;
  924.  
  925.     for( i = *str++; i--; )
  926.     {
  927.         *cstr++ = *str++;
  928.     }
  929.  
  930.     *cstr++ = ':';
  931.     *cstr = 0;
  932.     }
  933. #endif
  934.  
  935. }
  936.  
  937. /****************************************************************************************/
  938.  
  939. void REGARGS
  940. AddDiskNames( GlobData *glob, ULONG volreqflags )
  941. {
  942.     struct ReqEntry        *entry, *temp;
  943.     struct DosList        *dlist;
  944.     struct DeviceEntry        *deventry, *lastdeventry = NULL;
  945.     struct rtVolumeEntry    volentry;
  946.     UBYTE            /* *bstr, *cstr, */ name[ 42 ], devname[ 36 ];
  947.     /* WORD            i; */
  948.  
  949.     *glob->winaddr = ( APTR ) -1;
  950.     glob->maxvolwidth = 0;
  951.     dlist = LockDosList( LDF_VOLUMES | LDF_ASSIGNS | LDF_READ );
  952.  
  953.     while( ( dlist = NextDosEntry( dlist, LDF_VOLUMES | LDF_ASSIGNS | LDF_READ ) ) )
  954.     {
  955. #ifdef _AROS
  956.     GetVolName(dlist->dol_OldName, name);
  957. #else
  958.     GetVolName(dlist->dol_Name, name);
  959. #endif
  960.     if (dlist->dol_Type == DLT_VOLUME)
  961.     {
  962.         if (IsDosVolume(dlist) && !(volreqflags & VREQF_NODISKS))
  963.         {
  964.         if ((deventry = AllocDevEntry(glob, dlist, name)))
  965.         {
  966.             deventry->next = lastdeventry;
  967.             lastdeventry = deventry;
  968.         }
  969.         }
  970.     }
  971.     else if (dlist->dol_Type == DLT_DIRECTORY ||
  972.          dlist->dol_Type == DLT_NONBINDING)
  973.     {
  974.         if (!(volreqflags & VREQF_NOASSIGNS))
  975.         {
  976.         AddEntry(glob, glob->buff, name, -1, ASSIGN);
  977.         }
  978.     }
  979.     }
  980.  
  981.     /* Append device names to volumes */
  982.     dlist = LockDosList( LDF_DEVICES | LDF_READ );
  983.  
  984.     while( ( dlist = NextDosEntry( dlist, LDF_DEVICES | LDF_READ ) ) )
  985.     {
  986.     BOOL    devmatch;
  987.  
  988.     deventry = lastdeventry;
  989.     devmatch = FALSE;
  990.  
  991.     while( deventry )
  992.     {
  993. #ifdef _AROS
  994. #warning FIXME: AROS has no dol_Task!
  995. #else
  996.         devmatch |= ( deventry->task == dlist->dol_Task );
  997. #endif
  998. #ifdef _AROS
  999. #warning FIXME: AROS again has no dol_Task!
  1000.         if( !deventry->resolved && deventry->task && devmatch )
  1001. #else
  1002.         if( !deventry->resolved && deventry->task && ( deventry->task == dlist->dol_Task ) )
  1003. #endif
  1004.         {
  1005. #ifdef _AROS
  1006.         GetVolName( dlist->dol_OldName, devname );
  1007. #else
  1008.         GetVolName( dlist->dol_Name, devname );
  1009. #endif
  1010.         AddDisk( glob, deventry, devname, SIZE_CALCULATE, volreqflags );
  1011.         deventry->resolved = TRUE;
  1012.         }
  1013.  
  1014.         deventry = deventry->next;
  1015.     }
  1016.  
  1017.     if( !devmatch && ( volreqflags & VREQF_ALLDISKS ) &&
  1018.         !( volreqflags & VREQF_NODISKS ) && IsDosDevice( dlist ) )
  1019.     {
  1020.         /* Device seems to be a DOS disk device, and it didn't belong
  1021.          * to a volume, and we should really show all devices in a
  1022.          * volume requester.
  1023.          */
  1024. #ifdef _AROS
  1025.         GetVolName( dlist->dol_OldName, devname );
  1026. #else
  1027.         GetVolName( dlist->dol_Name, devname );
  1028. #endif
  1029.  
  1030.         if( ( deventry = AllocDevEntry( glob, dlist, "-" ) ) )
  1031.         {
  1032.         deventry->next = lastdeventry;
  1033.         lastdeventry = deventry;
  1034.         AddDisk( glob, deventry, devname, SIZE_NONE, volreqflags );
  1035.         deventry->resolved = TRUE;
  1036.         }
  1037.     }
  1038.     }
  1039.  
  1040.     UnLockDosList( LDF_DEVICES | LDF_READ );
  1041.     UnLockDosList( LDF_VOLUMES | LDF_ASSIGNS | LDF_READ );
  1042.  
  1043.     /* Free temp volume list (and add remaining names if ALLDISKS is on) */
  1044.     while( ( deventry = lastdeventry ) )
  1045.     {
  1046.     if( !deventry->resolved /* && ( !volreqflags || ( volreqflags & VREQF_ALLDISKS ) ) */ )
  1047.     {
  1048.         AddDisk( glob, deventry, "-", SIZE_CALCULATE, volreqflags );
  1049.     }
  1050.  
  1051.     lastdeventry = deventry->next;
  1052.     FreeVecPooled( glob->buff->pool, deventry );
  1053.     }
  1054.  
  1055.     /* If volume requester filter assigns */
  1056.     if( volreqflags && glob->filterhook )
  1057.     {
  1058.     entry = glob->buff->firstname;
  1059.  
  1060.     while( ( temp = entry ) )
  1061.     {
  1062.         entry = ( struct ReqEntry * ) entry->re_Next;
  1063.  
  1064.         if( !entry )
  1065.         {
  1066.         break;
  1067.         }
  1068.  
  1069.         if( entry->re_Type == ASSIGN )
  1070.         {
  1071.         volentry.Type = DLT_DIRECTORY;
  1072.         volentry.Name = entry->re_Name;
  1073.  
  1074.         if( !CallHookPkt( glob->filterhook, glob->freq, &volentry ) )
  1075.         {
  1076.             temp->re_Next = entry->re_Next;
  1077.             FreeVecPooled( glob->buff->pool, entry );
  1078.             entry = temp;
  1079.             glob->buff->currentnum--;
  1080.         }
  1081.         }
  1082.     }
  1083.     }
  1084.  
  1085.     *glob->winaddr = glob->reqwin;
  1086. }
  1087.  
  1088. /****************************************************************************************/
  1089.  
  1090. BOOL REGARGS FindCurrentPos (GlobData *glob, char *name, int size, int ctype)
  1091. {
  1092.     BOOL success;
  1093.  
  1094.     MarkHidden (glob);
  1095.     success = FindEntry (glob->buff, name, size, ctype, ( int * ) &glob->buff->pos, FIND_EXACT) ? TRUE : FALSE;
  1096.     glob->buff->gotopos = glob->buff->pos;
  1097.     
  1098.     return (success);
  1099. }
  1100.  
  1101. /****************************************************************************************/
  1102.  
  1103. void REGARGS NewDir (GlobData *glob)
  1104. {
  1105.     UnLockReqLock (glob);
  1106.     SetWindowTitles (glob->reqwin, glob->title, (char *)~0);
  1107.     FreeReqBuffer (glob->req);
  1108.     ClearDisplayList (glob);
  1109.     glob->newdir = TRUE;
  1110.     glob->clicked = ~0;
  1111.     
  1112.     if (glob->freq)
  1113.     {
  1114.     SetFileDirMode (glob->buff, glob->flags);
  1115.     glob->file_id = glob->buff->file_id;
  1116.     glob->directory_id = glob->buff->directory_id;
  1117.     }
  1118. }
  1119.  
  1120. /****************************************************************************************/
  1121.  
  1122. void REGARGS ShowDisks(GlobData *glob)
  1123. {
  1124.  
  1125.     if (!glob->disks)
  1126.     {
  1127.     UnLockReqLock (glob);
  1128.     FreeReqBuffer (glob->req);
  1129.     ClearAndInitReqBuffer (glob);
  1130.     glob->exnext = FALSE;
  1131.     glob->disks = TRUE;
  1132.     AddDiskNames (glob, glob->volumerequest);
  1133.     AdjustScroller (glob);
  1134.     UpdateDisplayList (glob);
  1135.     PrintFiles (glob);
  1136.     glob->buff->sorted = TRUE;
  1137.     glob->selectedpos = -1;
  1138.     }
  1139. }
  1140.  
  1141. /****************************************************************************************/
  1142.  
  1143. void REGARGS UpdateNumSelGad (GlobData *glob)
  1144. {
  1145.     int  top;
  1146.     char str[6];
  1147.  
  1148.     if (glob->numselectedgad)
  1149.     {
  1150.     Dofmt (str, "%4ld", &glob->numselected);
  1151.     
  1152.     SetAPen (glob->reqrp, glob->pens[TEXTPEN]);
  1153.     SetBPen (glob->reqrp, glob->pens[BACKGROUNDPEN]);
  1154.     SetDrMd (glob->reqrp, JAM2);
  1155.     
  1156.     top = glob->numselectedgad->TopEdge + 3;
  1157.     
  1158.     Move (glob->reqrp, glob->numselectedgad->LeftEdge + glob->numselectedoff + 8,
  1159.             top + glob->reqfont->tf_Baseline);
  1160.     Text (glob->reqrp, str, 4);
  1161.     
  1162.     SetDrMd (glob->reqrp, JAM2);
  1163.     SetAPen (glob->reqrp, glob->pens[BACKGROUNDPEN]);
  1164.     
  1165.     RectFill (glob->reqrp, glob->reqrp->cp_x,
  1166.                    top,
  1167.                    glob->numselectedgad->LeftEdge + glob->numselectedgad->Width - 3,
  1168.                    top + glob->fontheight - 1);
  1169.     }
  1170. }
  1171.  
  1172. /****************************************************************************************/
  1173.  
  1174. /*****************
  1175. * Font requester *
  1176. *****************/
  1177.  
  1178. /****************************************************************************************/
  1179.  
  1180. static struct Region *MyInstallRegion (struct Window *win, struct Region *reg, int refresh)
  1181. {
  1182.     struct Region *oldregion;
  1183.  
  1184.     if (refresh) GT_EndRefresh (win, FALSE);
  1185.     
  1186.     oldregion = InstallClipRegion (win->WLayer, reg);
  1187.     if (refresh) GT_BeginRefresh (win);
  1188.     
  1189.     return (oldregion);
  1190. }
  1191.  
  1192. /****************************************************************************************/
  1193.  
  1194. void REGARGS ShowFontSample (GlobData *glob, int refresh, int dowait)
  1195. {
  1196.     struct DiskfontBase *DiskfontBase = glob->diskfontbase;
  1197.     struct TextFont     *font;
  1198.     struct Rectangle     rect;
  1199.     struct Region     *oldregion, *region;
  1200.     char         *message = "0123 aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ";
  1201.     UWORD         *cmap = NULL;
  1202.     ULONG         style = glob->fontstyle, count = glob->colcount;
  1203.     APTR         winlock = NULL;
  1204.  
  1205.     if (dowait) winlock = rtLockWindow (glob->reqwin);
  1206.     
  1207.     if (glob->flags & FREQF_SCALE)
  1208.     glob->fontreq->Attr.ta_Flags &= ~FPF_DESIGNED;
  1209.     
  1210.     if (!(font = OpenDiskFont (&glob->fontreq->Attr)))
  1211.     {
  1212.     font = glob->reqfont;
  1213.     message = GetStr (glob->catalog, MSG_COULDNT_OPEN_FONT);
  1214.     style = 0;
  1215.     }
  1216.     
  1217.     rect.MinX = glob->fontdisplayleft;
  1218.     rect.MaxX = glob->fontdisplayright;
  1219.     rect.MinY = glob->fontdisplaytop;
  1220.     rect.MaxY = glob->fontdisplaytop + glob->sampleheight - 1;
  1221.  
  1222.     if ( ( region = NewRegion() ) )
  1223.     {
  1224.     OrRectRegion (region, &rect);
  1225.  
  1226.     oldregion = MyInstallRegion (glob->reqwin, region, refresh);
  1227.  
  1228.     SetFont (glob->reqrp, font);
  1229.     SetSoftStyle (glob->reqrp, style, ~0);
  1230.     SetAPen (glob->reqrp, glob->pens[TEXTPEN]);
  1231.     SetBPen (glob->reqrp, glob->pens[BACKGROUNDPEN]);
  1232.     
  1233.     if (font->tf_Style & FSF_COLORFONT)
  1234.     {
  1235.         struct ColorFontColors *cfc;
  1236.  
  1237.         cfc = ((struct ColorTextFont *)font)->ctf_ColorFontColors;
  1238.         count = cfc->cfc_Count;
  1239.         cmap = cfc->cfc_ColorTable;
  1240.     }
  1241.     
  1242.     if (glob->flags & FREQF_CHANGEPALETTE)
  1243.     {
  1244.         if (cmap) LoadRGB4 (glob->vp, cmap, count);
  1245.         else LoadCMap (glob->vp, glob->colormap);
  1246.     }
  1247.     
  1248.     if (!refresh) SetRast (glob->reqrp, glob->pens[BACKGROUNDPEN]);
  1249.     
  1250.     Move (glob->reqrp, glob->fontdisplayleft,
  1251.                glob->fontdisplaytop + (glob->sampleheight - font->tf_YSize) / 2
  1252.                         + font->tf_Baseline);
  1253.     Text (glob->reqrp, message, strlen(message));
  1254.  
  1255.     MyInstallRegion (glob->reqwin, oldregion, refresh);
  1256.     DisposeRegion (region);
  1257.  
  1258.     SetFont (glob->reqrp, glob->reqfont);
  1259.     SetSoftStyle (glob->reqrp, 0, ~0);
  1260.     }
  1261.  
  1262. /*endshowsample:*/
  1263.     CloseFont (font);
  1264.     if (dowait) rtUnlockWindow (glob->reqwin, winlock);
  1265. }
  1266.  
  1267. /****************************************************************************************/
  1268.  
  1269. /***********************
  1270. * ScreenMode requester *
  1271. ***********************/
  1272.  
  1273. /****************************************************************************************/
  1274.  
  1275. ULONG ASM myGetDisplayInfoData (
  1276.     OPT_REGPARAM(a1, UBYTE *, buf),
  1277.     OPT_REGPARAM(d0, unsigned long, size),
  1278.     OPT_REGPARAM(d1, unsigned long, tagID),
  1279.     OPT_REGPARAM(d2, unsigned long, displayID))
  1280. {
  1281.     return (GetDisplayInfoData (FindDisplayInfo (displayID),
  1282.                      buf, size, tagID, displayID));
  1283. }
  1284.  
  1285. /****************************************************************************************/
  1286.  
  1287. int REGARGS GetModeData (GlobData *glob, ULONG id, int *mon)
  1288. {
  1289.     struct MonitorInfo     monitorinfo;
  1290.     ULONG         propflags;
  1291.     int         modewidth, stdmode = TRUE;
  1292.     char         *str, *monstr;
  1293.  
  1294.     if ((myGetDisplayInfoData ((UBYTE *)&glob->diminfo,
  1295.                     sizeof (struct DimensionInfo), DTAG_DIMS, id) <= 0) ||
  1296.     (myGetDisplayInfoData ((UBYTE *)&glob->dispinfo,
  1297.                 sizeof (struct DisplayInfo), DTAG_DISP, id) <= 0))
  1298.     {
  1299.         return (FALSE);
  1300.     }
  1301.  
  1302.     modewidth = glob->diminfo.Nominal.MaxX - glob->diminfo.Nominal.MinX + 1;
  1303.     propflags = glob->dispinfo.PropertyFlags;
  1304.  
  1305.     if ((glob->flags & SCREQF_GUIMODES) && !(propflags & DIPF_IS_WB))
  1306.     return (FALSE);
  1307.  
  1308.     *mon = ((id & MONITOR_ID_MASK) >> 16) - 1;
  1309.  
  1310.     if (myGetDisplayInfoData ((UBYTE *)&glob->nameinfo,
  1311.                         sizeof (struct NameInfo), DTAG_NAME, id) <= 0)
  1312.     {
  1313.     str = glob->nameinfo.Name;
  1314.     if ((myGetDisplayInfoData ((UBYTE *)&monitorinfo, sizeof (struct MonitorInfo), DTAG_MNTR, id) > 0)
  1315.         && monitorinfo.Mspc)
  1316.     {
  1317.         monstr = monitorinfo.Mspc->ms_Node.xln_Name;
  1318.         while (*monstr > '.') *str++ = ToUpper (*monstr++);
  1319.         *str++ = ':';
  1320.     }
  1321.     
  1322.     DofmtArgs (str, "%ld x %ld", modewidth,
  1323.                          glob->diminfo.Nominal.MaxY - glob->diminfo.Nominal.MinY + 1);
  1324.                      
  1325.     if (propflags & DIPF_IS_HAM)
  1326.     {
  1327.         StrCat (str, GetStr (glob->catalog, MSG_DASH_HAM));
  1328.         stdmode = FALSE;
  1329.     }
  1330.     
  1331.     if (propflags & DIPF_IS_EXTRAHALFBRITE)
  1332.     {
  1333.         StrCat (str, GetStr (glob->catalog, MSG_DASH_EHB));
  1334.         stdmode = FALSE;
  1335.     }
  1336.     
  1337.     if (propflags & DIPF_IS_LACE)
  1338.         StrCat (str, GetStr (glob->catalog, MSG_DASH_INTERLACED));
  1339.  
  1340.     }
  1341.  
  1342.     /* check property flags using mask */
  1343.     if ((propflags & glob->propertymask) != (glob->propertyflags & glob->propertymask))
  1344.     return (FALSE);
  1345.  
  1346.     /* check if depth larger than minimum depth */
  1347.     if (glob->diminfo.MaxDepth < glob->mindepth) return (FALSE);
  1348.  
  1349.     /* GUI modes ? */
  1350.     if (glob->flags & SCREQF_GUIMODES)
  1351.     {
  1352.     return (stdmode && (modewidth >= 640));
  1353.     }
  1354.  
  1355.     /* include non-standard modes ? */
  1356.     if (!(glob->flags & SCREQF_NONSTDMODES)) return (stdmode);
  1357.  
  1358.     return (TRUE);
  1359. }
  1360.  
  1361. /****************************************************************************************/
  1362.  
  1363. void REGARGS SetTextGad (GlobData *glob, struct Gadget *gad, char *text)
  1364. {
  1365.     if (!gad) return;
  1366.     
  1367.     myGT_SetGadgetAttrs (gad, glob->reqwin, NULL, GTTX_Text, text,
  1368.                               TAG_END);
  1369. }
  1370.  
  1371. /****************************************************************************************/
  1372.  
  1373. void REGARGS SetSizeGads (GlobData *glob)
  1374. {
  1375.     if (glob->usedefwidth) glob->width = glob->defwidth;
  1376.     if (glob->usedefheight) glob->height = glob->defheight;
  1377.     if (glob->width > glob->maxwidth) glob->width = glob->maxwidth;
  1378.     if (glob->width < glob->minwidth) glob->width = glob->minwidth;
  1379.     
  1380.     my_SetIntegerGadget (glob->reqwin, glob->widthgad, glob->width);
  1381.     
  1382.     if (glob->height > glob->maxheight) glob->height = glob->maxheight;
  1383.     if (glob->height < glob->minheight) glob->height = glob->minheight;
  1384.     
  1385.     my_SetIntegerGadget (glob->reqwin, glob->heightgad, glob->height);
  1386. }
  1387.  
  1388. /****************************************************************************************/
  1389.  
  1390. LONG REGARGS IntGadgetBounds (GlobData *glob, struct Gadget *gad,
  1391.                           LONG min, LONG max)
  1392. {
  1393.     LONG val;
  1394.  
  1395.     val = ((struct StringInfo *)gad->SpecialInfo)->LongInt;
  1396.     
  1397.     if (val > max)
  1398.     {
  1399.     val = max;
  1400.     my_SetIntegerGadget (glob->reqwin, gad, val);
  1401.     }
  1402.     
  1403.     if (val < min)
  1404.     {
  1405.     val = min;
  1406.     my_SetIntegerGadget (glob->reqwin, gad, val);
  1407.     }
  1408.     
  1409.     return (val);
  1410. }
  1411.  
  1412. /****************************************************************************************/
  1413.  
  1414. int overscantrans[] = { 0, 3, 4, 1 };
  1415.  
  1416. /****************************************************************************************/
  1417.  
  1418. void REGARGS GetModeDimensions (GlobData *glob)
  1419. {
  1420.     struct Rectangle *rect;
  1421.  
  1422.     if (glob->modeid != INVALID_ID)
  1423.     {
  1424.     rect = &(&glob->diminfo.Nominal)[overscantrans[glob->overscantype]];
  1425.     glob->defwidth = rect->MaxX - rect->MinX + 1;
  1426.     glob->defheight = rect->MaxY - rect->MinY + 1;
  1427.     }
  1428.     else glob->defwidth = glob->defheight = 0;
  1429. }
  1430.  
  1431. /****************************************************************************************/
  1432.  
  1433. void BuildColStr (char *colstr, LONG colors, ULONG id)
  1434. {
  1435.     colors = 1 << colors;
  1436.  
  1437.     if (id & HAM)
  1438.     colors = (colors == 128 ? 4096 : 16777216L);
  1439.  
  1440.     if (id & EXTRA_HALFBRITE )
  1441.     colors = 64;
  1442.  
  1443.     if (colors <= 9999)
  1444.     {
  1445.     DofmtArgs (colstr, "%ld", colors);
  1446.     return;
  1447.     }
  1448.     
  1449.     colors /= 1024;
  1450.     if (colors <= 999)
  1451.     {
  1452.     DofmtArgs (colstr, "%ldK", colors);
  1453.     return;
  1454.     }
  1455.     
  1456.     colors /= 1024;
  1457.     
  1458.     DofmtArgs (colstr, "%ldM", colors);
  1459. }
  1460.  
  1461. /****************************************************************************************/
  1462.  
  1463. void REGARGS UpdateDepthDisplay (GlobData *glob, int depth, ULONG id)
  1464. {
  1465.     BuildColStr (glob->currcolstr, depth, id);
  1466.     
  1467.     myGT_SetGadgetAttrs (glob->currcolgad, glob->reqwin, NULL, GTTX_Text, glob->currcolstr,
  1468.                                        TAG_END);
  1469. }
  1470.  
  1471. /****************************************************************************************/
  1472.  
  1473. void REGARGS UpdateDepthGad (GlobData *glob)
  1474. {
  1475.     UpdateDepthDisplay (glob, glob->depth, glob->modeid);
  1476.     
  1477.     myGT_SetGadgetAttrs (glob->depthgad, glob->reqwin, NULL, GTSL_Min, glob->currmindepth,
  1478.                                          GTSL_Max, glob->currmaxdepth,
  1479.                                  GTSL_Level, glob->depth,
  1480.                                  GA_Disabled, (glob->currmindepth == glob->currmaxdepth),
  1481.                                  TAG_END);
  1482. }
  1483.  
  1484. /****************************************************************************************/
  1485.  
  1486. void REGARGS DisplayModeAttrs (GlobData *glob)
  1487. {
  1488.     if (glob->modeid != INVALID_ID)
  1489.     {
  1490.     int maxdepth = glob->diminfo.MaxDepth, mindepth = 1;
  1491.  
  1492.     if( maxdepth < 0 || maxdepth > 24 )
  1493.     {
  1494.         maxdepth = 24;
  1495.     }
  1496.  
  1497.     if (glob->depth > maxdepth || !(glob->flags & SCREQF_DEPTHGAD))
  1498.         glob->depth = maxdepth;
  1499.  
  1500.     /* if (glob->modeid & HAM) mindepth = maxdepth = glob->depth = 12; */
  1501.     /* if (glob->modeid & EXTRA_HALFBRITE) mindepth = maxdepth = glob->depth = 6; */
  1502.     
  1503.     if (glob->depthgad)
  1504.     {
  1505.         if (glob->modeid & EXTRA_HALFBRITE)
  1506.         {
  1507.         mindepth = maxdepth;
  1508.         }
  1509.  
  1510.         if (glob->modeid & HAM)
  1511.         {
  1512.         mindepth = 7;
  1513.  
  1514.         if (maxdepth == 6)
  1515.             ++maxdepth;
  1516.         }
  1517.  
  1518.         glob->currmaxdepth = maxdepth; glob->currmindepth = mindepth;
  1519.         
  1520.         if (glob->currmaxdepth > glob->maxdepth) glob->currmaxdepth = glob->maxdepth;
  1521.         if (glob->currmindepth < glob->mindepth) glob->currmindepth = glob->mindepth;
  1522.         if (glob->depth > glob->currmaxdepth) glob->depth = glob->currmaxdepth;
  1523.         if (glob->depth < glob->currmindepth) glob->depth = glob->currmindepth;
  1524.         
  1525.         UpdateDepthGad (glob);
  1526.         BuildColStr (glob->maxcolstr, glob->currmaxdepth, glob->modeid);
  1527.         myGT_SetGadgetAttrs (glob->maxcolgad, glob->reqwin, NULL,
  1528.                 GTTX_Text, glob->maxcolstr, TAG_END);
  1529.     }
  1530.     SetSizeGads (glob);
  1531.     
  1532.     } /* if (glob->modeid != INVALID_ID) */
  1533. }
  1534.  
  1535. /****************************************************************************************/
  1536.